iT邦幫忙

2021 iThome 鐵人賽

DAY 7
0

今天就來教大家一些比較簡單的數學運算,因為有很多的數學用法都沒辦法以鍵盤上的符號來代替,例如:開根號、求餘。所以就有很多的特殊用法需要記起來,那我就幫大家整理在下面。那當然數學裡常見的括弧,用法也是一樣的。
加法 +
減法 -
乘法 *
次方 **
除法 /
除法求餘 %
除法求商 //
https://ithelp.ithome.com.tw/upload/images/20210907/20140468zYwxgz1Phe.png

print(7+2)
print(7-2)
print(7*2)
print(7**2)
print(7/2)
print(7%2)
print(7//2)

上面是簡單的示範,那現在就來做一些簡單的題目吧

1.輸入三個科目的考試成績(都為整數),求三科考試成績平均分數,並打印出結果
https://ithelp.ithome.com.tw/upload/images/20210907/20140468pD2vkgficl.png

a=int(input('輸入考試成績:')
b=int(input('輸入考試成績:')
c=int(input('輸入考試成績:')
print('平均成績為:',(a+b+c)/3)

2.輸入數字a和b,求a的b次方
https://ithelp.ithome.com.tw/upload/images/20210907/20140468jG8nPFFLkc.png

a=int(input('輸入數字a:'))
b=int(input('輸入數字b:'))
print('a的b次方為:',a**b)

上一篇
Python 輸入資料
下一篇
Python for迴圈
系列文
一起來探索Python語言30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言